

import java.awt.Graphics;

public class ydLine {

	ydPoint slope;
	ydPoint p1, p2;
	double length;
	double angle;
	
	
	//Old Version
	public ydLine(){
		slope=new ydPoint();
		p1=new ydPoint();
	}
	
	/*public ydLine(ydPoint s, ydPoint p){
		slope=new ydPoint(s);
		p1=new ydPoint(p);
	}*/
	
	public void drawLine(Graphics g){
		
		g.drawString("P1: " + p1.toString(), 10, 40);
		g.drawString("P2: " + p2.toString(), 10, 50);
		g.drawString("slope: " + slope.toString(), 10, 60);
		g.drawString("Angle: " + angle + "", 10, 70);
		g.drawString("Length: " + length + "", 10, 80);
		
		g.drawLine((int)p1.x, (int)p1.y, (int)(p2.x), (int)(p2.y));
	}
	
	
	//New Methods
	
	public ydLine(ydLine l1){
		p1=new ydPoint(l1.p1);
		p2=new ydPoint(l1.p2);
		
		slope=ydMath.slopeOf(p1, p2);
		slope.normailize();
		
		length=ydMath.hypotenuse(p1, p2);
		angle=ydMath.vectorToDegrees(slope);
	}
	
	public ydLine(ydPoint p1, ydPoint p2){
		this.p1=new ydPoint(p1);
		this.p2=new ydPoint(p2);
		
		slope=ydMath.slopeOf(p1, p2);
		slope.normailize();
		
		length=ydMath.hypotenuse(p1, p2);
		angle=ydMath.vectorToDegrees(slope);
	}
	
	public ydLine(ydPoint p1, double length){
		this.p1=new ydPoint(p1);
		this.length=length;
		this.p2=new ydPoint(p1.x, (float) (p1.y+length));
		
		slope=ydMath.slopeOf(p1, p2);
		slope.normailize();

		angle=ydMath.vectorToDegrees(slope);
	}
	
	public void recalculate(){
		slope=ydMath.slopeOf(p1, p2);
		slope.normailize();

		angle=ydMath.vectorToDegrees(slope);
	}
	
	
	public void deltaMove(ydPoint shift) {
		p1.x += shift.x;
		p1.y += shift.y;

		p2.x += shift.x;
		p2.y += shift.y;


	}

	public void move(ydPoint shift) {

		p1.x = shift.x;
		p1.y = shift.y;

		p2.x = (float) (p1.x + slope.x*length);
		p2.y = (float) (p1.y+ slope.y*length);

	}
	
	public void move(ydPoint shift, int i) {

		p2.x = shift.x;
		p2.y = shift.y;

		p1.x = (float) (p2.x + -slope.x*length);
		p1.y = (float) (p2.y+ -slope.y*length);

	}
	
	public void rotate(ydPoint pivot, double rads){
		p1.rotatePointAround(pivot, (float)rads);
		p2.rotatePointAround(pivot, (float)rads);
		
		slope=ydMath.slopeOf(p1, p2);
		slope.normailize();
		
		length=ydMath.hypotenuse(p1, p2);
		angle=ydMath.vectorToDegrees(slope);
	}
	
	public void rotate(double rads){
		ydPoint pivot=p1;
		
		p1.rotatePointAround(pivot, (float)rads);
		p2.rotatePointAround(pivot, (float)rads);
		
		slope=ydMath.slopeOf(p1, p2);
		slope.normailize();
		
		length=ydMath.hypotenuse(p1, p2);
		angle=ydMath.vectorToDegrees(slope);
	}
	
	public void deltaRotate(ydPoint pivot, double rads){
		p1.rotatePointAround(pivot, -ydMath.vectorToRads(slope));
		p2.rotatePointAround(pivot, -ydMath.vectorToRads(slope));
		
		p1.rotatePointAround(pivot, (float)rads);
		p2.rotatePointAround(pivot, (float)rads);
		
		slope=ydMath.slopeOf(p1, p2);
		slope.normailize();
		
		length=ydMath.hypotenuse(p1, p2);
		angle=ydMath.vectorToDegrees(slope);
	}
	
	
	
}
